package feedback.core.models.entities; /***********************************************************************
 * Module:  Student.java
 * Author:  lufy
 * Purpose: Defines the Class Student
 ***********************************************************************/

import javax.persistence.*;
import java.io.Serializable;
import java.util.*;
@Entity
@PrimaryKeyJoinColumn(name="studentId")
public class Student extends Person implements Serializable {
   private String studentState;
   @ManyToOne(fetch = FetchType.LAZY,cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
   private Coat coat;
   @ManyToMany(fetch = FetchType.LAZY,cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH} ,mappedBy = "student")
   private List<ClassRoom> classRooms;
   @OneToMany(fetch = FetchType.LAZY,cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},mappedBy = "student")
   public List<SurveyResult> surveyResult;

   @Override
   public String is() {
      return "st";
   }

   public Student() {
   }

   public Student(String studentState, Coat coat, List<ClassRoom> classRooms, List<SurveyResult> surveyResult) {
      this.studentState = studentState;
      this.coat = coat;
      this.classRooms = classRooms;
      this.surveyResult = surveyResult;
   }

   public Student(int personId, String personNo, String personName, String personPass, String personMail, String gender, Date personBrithDay, String personAddress, String personPhone, String studentState, Coat coat, List<ClassRoom> classRooms, List<SurveyResult> surveyResult) {
      super(personId, personNo, personName, personPass, personMail, gender, personBrithDay, personAddress, personPhone);
      this.studentState = studentState;
      this.coat = coat;
      this.classRooms = classRooms;
      this.surveyResult = surveyResult;
   }

 

   public String getStudentState() {
      return studentState;
   }

   public void setStudentState(String studentState) {
      this.studentState = studentState;
   }

   public Coat getCoat() {
      return coat;
   }

   public void setCoat(Coat coat) {
      this.coat = coat;
   }

   public List<ClassRoom> getClassRooms() {
      if(this.classRooms==null){
         return  new ArrayList<ClassRoom>();
      }
      return classRooms;
   }

   public void setClassRooms(List<ClassRoom> classRooms) {
      this.classRooms = classRooms;
   }
   public  void addClassRoom(ClassRoom newClassRoom){
      if(newClassRoom ==null){
         return;
      }
      if(this.classRooms==null){
         this.classRooms = new ArrayList<ClassRoom>();
      }
      if (!this.classRooms.contains(newClassRoom)){
         this.classRooms.add(newClassRoom);
      }
   }
   public void removeClassRoom(ClassRoom oldClassRoom){
      if(oldClassRoom == null){
         return;
      }
      if(this.classRooms!=null){
         if(this.classRooms.contains(oldClassRoom)){
            this.classRooms.remove(oldClassRoom);
         }
      }
      oldClassRoom.removeStudent(this);
   }
   public void removeAllClassRoom(){
      if(this.classRooms!=null){
         classRooms.clear();
      }
   }

   public List<SurveyResult> getSurveyResult() {
      if(this.surveyResult==null){
         return new ArrayList<SurveyResult>();
      }
      return surveyResult;
   }

   public void setSurveyResult(List<SurveyResult> surveyResult) {
      this.surveyResult = surveyResult;
   }
   public void addSurveyResult(SurveyResult newSurveyResult) {
      if (newSurveyResult == null)
         return;
      if (this.surveyResult == null)
         this.surveyResult = new ArrayList<SurveyResult>();
      if (!this.surveyResult.contains(newSurveyResult))
         this.surveyResult.add(newSurveyResult);
      newSurveyResult.setStudent(this);
   }

   public void removeSurveyResult(SurveyResult oldSurveyResult) {
      if (oldSurveyResult == null)
         return;
      if (this.surveyResult != null)
         if (this.surveyResult.contains(oldSurveyResult))
            this.surveyResult.remove(oldSurveyResult);
   }

   public void removeAllSurveyResult() {
      if (surveyResult != null)
         surveyResult.clear();
   }

@Override
public boolean isTeacher() {
	// TODO Auto-generated method stub
	return false;
}

@Override
public boolean isStudent() {
	// TODO Auto-generated method stub
	return true;
}

}